#pragma once
#include "afxsock.h"

class CClientSocket :
	public CAsyncSocket
{
public:


public:
	typedef void (*PFNCALLBACK)(CClientSocket*, long, WPARAM, LPARAM);

public:
	CClientSocket(BOOL bClient=TRUE);
	virtual ~CClientSocket();

public:
	void SetCallback(PFNCALLBACK pfnCallback, WPARAM wParam=0, LPARAM lParam=0);
	BOOL IsConnected();
	BOOL BeginSend(char *pBuf, int nBufLen);
	BOOL BeginReceive(char *pBuf, int nBufLen);
	virtual void Close();

protected:
	typedef struct tagDATA
	{
		char *pBuf;
		int nBufLen;
	} DATA, *PDATA;

protected:
	virtual void OnConnect(int nErrorCode);
	virtual void OnClose(int nErrorCode);
	virtual void OnSend(int nErrorCode);
	virtual void OnReceive(int nErrorCode);

protected:
	BOOL m_bConnected;
	PFNCALLBACK m_pfnCallback;
	WPARAM m_wParam;
	LPARAM m_lParam;
	long m_lEvent;
	CList<DATA> m_listSend, m_listRecv;
};
